package com.example.mapinformationandroid.UI;

import androidx.appcompat.app.AppCompatActivity;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentManager;
import androidx.fragment.app.FragmentTransaction;

import android.content.Intent;
import android.os.Bundle;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.bumptech.glide.request.RequestOptions;
import com.example.mapinformationandroid.Model.Bean.InformationBean;
import com.example.mapinformationandroid.Model.Comment;
import com.example.mapinformationandroid.Model.Information;
import com.example.mapinformationandroid.R;
import com.example.mapinformationandroid.UI.Fragment.FragmentComment;

public class InformationDetails extends AppCompatActivity implements FragmentComment.OnListFragmentInteractionListener {
    private TextView title,content;
    private ImageView imageView;
    private Fragment fragment_comment;
    private InformationBean information;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_information_details);
        initData();
        initView();
        setFragment();

    }
    private void initData(){
        Intent intent = this.getIntent();
        Bundle bundle = intent.getBundleExtra("message");
        information = (InformationBean) bundle.getSerializable("information");
    }


    private void initView(){
        title = findViewById(R.id.tv_information_title);
        content = findViewById(R.id.tv_information_content);
        imageView = findViewById(R.id.img_information_picture);
        title.setText(information.getTitle());
        content.setText(information.getContent());
        RequestOptions options = new RequestOptions();
        options.placeholder(R.drawable.defult_information); //添加占位图
        options.error(R.drawable.defult_information)
                .centerCrop();
        Glide.with(this)
                .load(information.getPicture())
                .apply(options)
                .into(imageView);
    }
    private void setFragment(){
        FragmentManager fragmentManager = getSupportFragmentManager();
        FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
        fragmentTransaction.add(R.id.fragment_comment,new FragmentComment()).commit();
    }

    @Override
    public void onListFragmentInteraction(Comment item) {

    }
}
